package comag

import "sync/atomic"

type StopNotifyWorker struct {
	StopWorker
	ch chan bool
}

func (w *StopNotifyWorker) Stop() {
	w.StopWorker.Stop()
	if w.ch == nil {
		w.ch = make(chan bool, 1)
	}
	close(w.ch)
}

func (w *StopNotifyWorker) StopNotify() chan bool {
	if w.ch == nil {
		w.ch = make(chan bool, 1)
	}
	return w.ch
}

type StopWorker struct {
	sig int32 //0:运行中，1:已停止
}

func (w *StopWorker) Start() {
	atomic.StoreInt32(&w.sig, 0)
}

func (w *StopWorker) Stop() {
	atomic.StoreInt32(&w.sig, 1)
}

func (w *StopWorker) Stopped() bool {
	return atomic.LoadInt32(&w.sig) == 1
}
